package com.kexio.common.page;

/**
 * 统一分页工具（与具体 ORM 解耦）。
 */
public final class PageUtils {

    private static final long DEFAULT_PAGE_NO = 1L;
    private static final long DEFAULT_PAGE_SIZE = 10L;
    private static final long DEFAULT_MAX_SIZE = 100L;

    private PageUtils() {}

    public static long normalizePageNo(Long current) {
        return (current != null && current > 0L) ? current : DEFAULT_PAGE_NO;
    }

    public static long normalizePageSize(Long size) {
        long val = (size != null && size > 0L) ? size : DEFAULT_PAGE_SIZE;
        return Math.min(val, DEFAULT_MAX_SIZE);
    }

    public static long current(PageQuery pageQuery) {
        return normalizePageNo(pageQuery != null ? pageQuery.getCurrent() : null);
    }

    public static long size(PageQuery pageQuery) {
        return normalizePageSize(pageQuery != null ? pageQuery.getSize() : null);
    }
}


